<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/25 0025
 * Time: 9:19
 */
namespace app\adminapi\controller;

use app\adminapi\model\Api;
use think\App;
use think\Controller;
use think\helper\Hash;
use think\Db;
use think\Session;
use app\adminapi\model\Role as RoleModel;
use app\adminapi\model\Menu as MenuModel;

/**
 * @title 后台权限管理
 * @description 接口说明
 * @header name:flag require:1 default: desc:手机设备号
 */
class Authority extends Api
{
    /**
     * @title 角色管理
     * @description 接口说明
     * @author 开发者
     * @url /adminapi/authority/index
     * @method POST
     * 
     * @return list:列表@
     * @list id:id pid:上级id若没有为超级管理员 name:角色名 description:描述 num:员工数量
     */
   public function index()
   {
        $user = $this->user;
        $where[] = ['hid','=',$user['hid']];
        // 角色
        $role =  db::name('admin_role')->where($where)->field('id,pid,name,description')->select();
        foreach ($role as $k => $v) {
            $where[] = ['role','=',$v['id']];
            $role[$k]['num'] = db::name('user')->where($where)->count();
        }
        $data['list'] = $role;
        return $this->ajaxReturn(0,'成功',$data);
   }
   /**
     * @title 添加角色获取权限（未补充）
     * @description 接口说明
     * @author 开发者
     * @url /adminapi/authority/get_role
     * @method POST
     * 
     */
    public function get_role()
    {
        $user = $this->user;
        // $res = RoleModel::getTree(null, false, session('user_authaa.role'));
        $data['menu_auth'] = [];
        
       
    }
}